<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1
        let arr = [1, [2, 3, 4, [5, 6, [7]]]]
        function my(arr) {
            let to = []
            for (var v of arr) {
                if (Array.isArray(v)) {
                    to.push.apply(to, my(v))
                } else {
                    to.push(v)
                }
            }
            return to
        }
        console.log(my(arr));

        // 2
        let str = JSON.stringify(arr)
        console.log(str);
        let str1 = str.replace(/\[|\]/g, '')
        str1 = JSON.parse('[' + str1 + ']')
        console.log(str1);
    </script>
</body>

</html>